/**
 * 
 */
package com.bestbuy.daoimple;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.bestbuy.dao.CommentDao;
import com.bestbuy.pojo.Comment;

/**
 * @author ThanhNgo
 *
 */
@Repository
@SuppressWarnings({"unchecked", "rawtypes"})
public class CommentDaoImpl implements CommentDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	public void addComment(Comment comment) {
		Session session = sessionFactory.getCurrentSession();
		session.save(comment);
	}

	public List<Comment> getListComment(String idProduct) {
		// TODO Auto-generated method stub
		Session session = sessionFactory.getCurrentSession();
		String hql = "from Comment where product.idproduct = ?";
		Query query = session.createQuery(hql);
		query.setString(0, idProduct);
		List list = query.list();
		return list;
	}

}
